<template>

  <el-select
    v-model="floorId"
    placeholder="请选择楼层"
    filterable
    clearable
    :disabled="disabled"
  >
    <el-option
      v-for="dict in floorList"
      :key="dict.id"
      :label="dict.floorName"
      :value="dict.id"
    />
  </el-select>


</template>

<script>
import {getAccommodationFloorPage} from "@/api/collegebase/accommodationFloor";

export default {
  name: "FloorSelector",
  props: {
    value: {
      type: String,
      default: ''
    },
    disabled: {
      type: Boolean,
      default: false
    },
    buildingId: {
      type: String,
      default: ''
    },
  }
  ,
  model: {
    prop: 'value',
    event: 'change'
  },
  data() {
    return {
      floorList: [],
      floorId: '',
    };
  },

  created() {
  },

  watch: {
    floorId(value) {
      this.$emit('change', value)
    },
    buildingId: {
      immediate: true,
      handler(newVal, oldVal) {
        if (oldVal) {
          this.floorId = '';
        } else {
          this.floorId = this.value;
        }
        this.getFloorListData(newVal);
      }
    },
    value(value) {
      // console.info("专业 执行value 操作：", value)
      this.floorId = value;
    }
  },
  methods: {
    //获取
    async getFloorListData(buildingId) {
      if (null == buildingId || '' == buildingId) {
        this.floorList = []
        return;
      }
      const rootRespList = await getAccommodationFloorPage({
        buildingId,
        pageNo: 1,
        pageSize: 99,
      });
      this.floorList = rootRespList.data.list;
    },

    clear() {
      this.$emit("change", '')
    }


  }

}
</script>

